package model

import (
	"gorm.io/gorm"
	"time"
)

type Chat struct {
	gorm.Model               // 包含 ID、CreatedAt、UpdatedAt、DeletedAt 字段
	Name          string     `gorm:"type:varchar(100);not null;comment:聊天名称" json:"name"`
	UserId        uint       `gorm:"not null;index;comment:所属用户ID" json:"user_id"`
	Provider      string     `gorm:"type:varchar(64);not null;comment:AI提供商" json:"provider"`
	AIModel       string     `gorm:"type:varchar(64);not null;comment:具体模型" json:"ai_model"`
	SystemPrompt  string     `gorm:"type:varchar(512);comment:系统提示词" json:"system_prompt,omitempty"`
	Description   string     `gorm:"type:varchar(512);comment:对话描述" json:"description,omitempty"`
	MessageCount  int        `gorm:"default:0;comment:消息数量" json:"message_count"`
	Hide          int        `gorm:"default:0;comment:是否隐藏;column:is_hide;type:tinyint(1);" json:"is_hide"`
	LastMessageAt *time.Time `gorm:"comment:最后消息时间" json:"last_message_at,omitempty"`
}

func NewChat(name string, id uint) *Chat {
	return &Chat{Name: name, UserId: id}
}

func (Chat) TableName() string {
	return "t_chat"
}
